package com.photoeditor.demo.model.subscribe.strategy;


import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.common.commercialize.strategy.bean.StrategyBean;
import com.photoeditor.demo.model.subscribe.manager.SVipConstant;
import com.photoeditor.demo.model.subscribe.manager.SkuManager;

import org.json.JSONObject;

/**
 * Created by Lai on 2018/10/24 0024.
 */
public class SVipStrategyBean extends StrategyBean<SVipStrategyBean.StrategyBeanConfig> {

    public SVipStrategyBean() {
    }

    @Override
    protected StrategyBeanConfig makeConfig(@NonNull JSONObject jsonObject) {
        return SVipStrategyBean.StrategyBeanConfig.make(jsonObject);
    }

    public static class StrategyBeanConfig extends StrategyBean.Config {

        private final int TRUE = 1;
        private final int FALSE = 0;
        //没有获取策略时客户端默认的状态
        private @SVipConstant.SVipPage int mDefaultPageId;
        private int mDefaultPayColor;
        private int mDefaultDesColor;

        /**
         * 区分策略控制位置的id：判断是挽留弹唱还是主订阅页还是功能订阅页
         *     public static final int VIP_ENTRANCE_IN_APP = 1;
         *     public static final int VIP_ENTRANCE_RETAIN = 2;
         *     public static final int VIP_ENTRANCE_FUNCTION_SUBSCRIBE = 3;

         */
        private int mEntranceId;
        private static final String ENTRANCE_ID = "sub_enter";

        //订阅开关--（开-TRUE,关-FALSE）
        private boolean mOpen = true;
        private static final String OPEN = "sub_open";

        //每日展示次数
        private int mShowCountToday;
        private static final String SHOW_COUNT_TODAY = "retain_showtime";

        //首选订阅类型--年费（annual）,月费（month）
        private int mFirstSub;
        private static final String FIRST_SUBSCRIBE = "sub_type";

        //付费文案的颜色深浅
        private int mPayColor=-1;
        private static final String PAY_COLOR = "pay_t_color";

        //介绍文案的颜色深浅
        private int mDesColor=-1;
        private static final String DES_COLOR = "des_t_color";



        /*
            哪个订阅页（订阅视频还是图片轮播）和哪一个挽留弹窗（A or B）
            public static final int VIP_ACTIVITY_A = 101;
            public static final int VIP_ACTIVITY_B = 102;

            public static final int VIP_DIALOG_A = 201;
            public static final int VIP_DIALOG_B = 202;
        *
        * */
        private int mTestPageId;
        private static final String TEST_PAGE_ID = "mainsub_type";


        public StrategyBeanConfig() {
        }

        public StrategyBeanConfig(int entranceId, @SVipConstant.SVipPage int defaultPageId, boolean showTipText) {
            mEntranceId = entranceId;
            mDefaultPageId = defaultPageId;
        }

        public StrategyBeanConfig(boolean open, int entranceId, @SVipConstant.SVipPage int defaultPageId,@SVipConstant.SVipPage int defaultPayColor,@SVipConstant.SVipPage int defaultDesColor, boolean showTipText) {
            mOpen = open;
            mEntranceId = entranceId;
            mDefaultPageId = defaultPageId;
            mDefaultPayColor=defaultPayColor;
            mDefaultDesColor=defaultDesColor;
        }

        //功能订阅页
        public StrategyBeanConfig(boolean open, int entranceId, @SVipConstant.SVipPage int defaultPayColor,@SVipConstant.SVipPage int defaultDesColor, boolean showTipText) {
            mOpen = open;
            mEntranceId = entranceId;
            mDefaultPayColor=defaultPayColor;
            mDefaultDesColor=defaultDesColor;
        }


        public StrategyBeanConfig(int entranceId, boolean open, @SVipConstant.SVipPage int defaultPageId,@SVipConstant.SVipPage int defaultPayColor,@SVipConstant.SVipPage int defaultDesColor, int showCountToday, boolean showTipText) {
            mOpen = open;
            mEntranceId = entranceId;
            mDefaultPageId = defaultPageId;
            mDefaultPayColor=defaultPayColor;
            mDefaultDesColor=defaultDesColor;
            mShowCountToday = showCountToday;
        }



        public void update(StrategyBeanConfig config) {
            if (config.mEntranceId > 0) {
                mEntranceId = config.mEntranceId;
            }
            if (config.mShowCountToday > 0) {
                mShowCountToday = config.mShowCountToday;
            }
            if (config.mFirstSub > 0) {
                mFirstSub = config.mFirstSub;
            }
            if (config.mTestPageId > 0) {
                mTestPageId = config.mTestPageId;
            }
            if (config.mPayColor >=0) {
                mPayColor = config.mPayColor;
            }
            if (config.mDesColor >=0) {
                mDesColor = config.mDesColor;
            }
            mOpen = config.mOpen;
        }

        @Override
        protected void analysis(@NonNull JSONObject jsonObject) {
            super.analysis(jsonObject);
            mEntranceId = jsonObject.optInt(ENTRANCE_ID, -1);
            mOpen = jsonObject.optBoolean(OPEN, true);
            mShowCountToday = jsonObject.optInt(SHOW_COUNT_TODAY, -1);
            mPayColor = jsonObject.optInt(PAY_COLOR, -1);
            mDesColor = jsonObject.optInt(DES_COLOR, -1);
            String subTyptStr = jsonObject.optString(FIRST_SUBSCRIBE, SkuManager.TYPE_MONTH);
            if(subTyptStr.equals(SkuManager.TYPE_MONTH)){
                mFirstSub=SkuManager.TYPE_MONTHLY;
            }else{
                mFirstSub=SkuManager.TYPE_YEARLY;
            }
            mTestPageId = jsonObject.optInt(TEST_PAGE_ID, -1);

        }

        public int getEntranceId() {
            return mEntranceId;
        }

        public void setEntranceId(int entranceId) {
            mEntranceId = entranceId;
        }


        public boolean isOpen() {
            return mOpen;
        }

        public void setOpen(boolean open) {
            mOpen = open;
        }

        public int getDefaultPageId() {
            return mDefaultPageId;
        }

        public void setDefaultPageId(int defaultPageId) {
            mDefaultPageId = defaultPageId;
        }

        public int getDefaultPayColor() {
            return mDefaultPayColor;
        }

        public void setDefaultPayColor(int defaultPayColor) {
            mDefaultPayColor = defaultPayColor;
        }

        public int getDefaultDesColor() {
            return mDefaultDesColor;
        }

        public void setDefaultDesColor(int defaultDesColor) {
            mDefaultDesColor = defaultDesColor;
        }

        public int getShowCountToday() {
            return mShowCountToday;
        }

        public void setShowCountToday(int showCountToday) {
            mShowCountToday = showCountToday;
        }

        public int getFirstSub() {
            return mFirstSub;
        }

        public void setFirstSub(int firstSub) {
            mFirstSub = firstSub;
        }

        public int getTestPageId() {
            return mTestPageId;
        }

        public void setTestPageId(int testPageId) {
            mTestPageId = testPageId;
        }

        public int getPayColor() {
            return mPayColor;
        }

        public void setPayColor(int payColor) {
            mPayColor = payColor;
        }

        public int getDesColor() {
            return mDesColor;
        }

        public void setDesColor(int desColor) {
            mDesColor = desColor;
        }


        public static SVipStrategyBean.StrategyBeanConfig make(@NonNull JSONObject var0) {
            SVipStrategyBean.StrategyBeanConfig var1 = new SVipStrategyBean.StrategyBeanConfig();
            var1.analysis(var0);
            return var1;
        }

    }

}
